home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / langwn23.zip / SAMPLE03.BAS < prev    next >
BASIC Source File  |  1993-02-11  |  6KB  |  215 lines

  1. DECLARE SUB ShowMouseData (Button%, Horiz%, Vert%)
  2. DECLARE SUB MousDemo ()
  3. '============================================================================
  4. '============================================================================
  5.  
  6. ' sample code 03 to demonstrate techniques for using
  7. ' the mouse routines in LangWin
  8.  
  9. ' hit Shift+F5 to run this code.
  10. ' follow instructions displayed on screen.
  11.  
  12. ' you must start QuickBASIC as follows:  qb /ah /L langwin
  13. '    /L langwin parameter provides access to LangWin quicklib
  14. '    /ah parameter is needed to allow dynamic arrays > 64k.
  15.  
  16. DEFINT A-Z
  17.  
  18. '$INCLUDE: 'LANGWIN.BI' ' TYPE, DECLARE and COMMON definitions for LangWin.
  19. '                         NOTE: LANGWIN.BI contains all definitions found
  20. '                               in QB.BI, so include for QB.BI is not needed.
  21.  
  22.  
  23. ' get attribute from row 1, col1 so it can be restored upon exit
  24. OrigAttr = SCREEN(1, 1, 1)' save original attribute on screen
  25.  
  26. ' see if we have a mouse
  27. HaveMouse = FALSE     ' default switch to no mouse
  28. IF MouseExists THEN
  29.   IF InitMouse(x) THEN
  30.     HaveMouse = TRUE     ' set switch
  31.   END IF
  32. END IF
  33.  
  34.  
  35. LOCATE , , 0             ' start with hidden text cursor
  36.  
  37. SCREEN 0                 ' text mode
  38.  
  39.  
  40. ' sample mouse routines
  41. CALL MousDemo
  42.  
  43.  
  44.  
  45. ' resoure original screen colors and exit
  46. bbb = (OrigAttr AND &HF0) \ 16  ' mask & shift to get original background
  47. fff = OrigAttr AND &HF          ' mask to get original foreground
  48.  
  49.  
  50. PALETTE                           ' restore original palette
  51. CALL SetColor(fff, bbb)           ' restore orig foreground/background
  52. CLS
  53. LOCATE , , 1                      ' make text cursor visible
  54.  
  55.  
  56.  
  57. END
  58.  
  59. '
  60. '   demonstrate mouse routines from LangWin
  61. '   the WaitTicks routine is also used to demonstrate
  62. '   how to generate a small delay.
  63. '
  64. SUB MousDemo
  65.  
  66. CLS
  67. LOCATE 1, 1, 0  ' turn off text cursor
  68. INPUT "Hit enter to see mouse pointer.", a$
  69. LOCATE 1, 1
  70. PRINT "Use GetMousePos to get current mouse data in real-time."
  71. PRINT "Mouse data is shown at bottom of screen."
  72. PRINT "Move mouse, click buttons, notice changes in data below."
  73. PRINT "Hit any key to terminate this test."
  74.  
  75. ' print mask
  76. LOCATE 25, 1
  77. PRINT "Horiz: xxx   Vert: xxx    Left: xxxx    Right: xxxx    Center: xxxx ";
  78.  
  79. IF HaveMouse THEN CALL ShowMouseCursor ' display mouse pointer
  80. DO
  81.   CALL GetMousePos(Button, Horiz, Vert)  ' LangWin routine to get mouse data
  82.   CALL ShowMouseData(Button, Horiz, Vert)  'local routine to display data
  83. LOOP WHILE INKEY$ = ""
  84. IF HaveMouse THEN CALL HideMouseCursor 'hide mouse pointer while writing to screen
  85.  
  86.  
  87.  
  88. LOCATE 1, 1
  89. PRINT "Use SetXLimit and SetYLimit to restrict area for mouse pointer."
  90. PRINT "Hit any key to terminate this test.        "
  91. PRINT SPACE$(70);  ' clear line 3
  92. PRINT SPACE$(70);  ' clear line 4
  93.  
  94. ' limit mouse pointer
  95. CALL SetXLimit(20, 100)
  96. CALL SetYLimit(50, 100)
  97.  
  98. LOCATE 10, 40
  99. PRINT "$", "Click here to see tomorrow's"
  100. LOCATE 11, 43
  101. PRINT "winning lottery number!!"
  102.  
  103.  
  104. IF HaveMouse THEN CALL ShowMouseCursor ' display mouse pointer
  105. DO
  106.   CALL GetMousePos(Button, Horiz, Vert)  ' LangWin routine to get mouse data
  107.   CALL ShowMouseData(Button, Horiz, Vert)  'local routine to display data
  108. LOOP WHILE INKEY$ = ""
  109. IF HaveMouse THEN CALL HideMouseCursor 'hide mouse pointer while writing to screen
  110.  
  111.  
  112. ' un-limit mouse pointer
  113. CALL SetXLimit(0, 639)
  114. CALL SetYLimit(0, 199)
  115.  
  116.  
  117.  
  118. LOCATE 1, 1
  119. CLS
  120. LOCATE 1, 1
  121. PRINT "Now let's use GetButtonPress to count button presses"
  122. PRINT "(useful to determine a double click) and determine"
  123. PRINT "coordinates of the last press."
  124. LOCATE 6, 1
  125. PRINT "While the following bar is shrinking, move mouse around screen."
  126. PRINT "Click left button a few times in various positions."
  127. PRINT "When bar vanishes, I'll show the total number of presses"
  128. PRINT "and the coordinates of the last press."
  129. LOCATE 11, 1
  130. PRINT "Hit any key to start test."
  131. DO: LOOP WHILE INKEY$ = ""
  132. LOCATE 11, 1
  133. PRINT SPACE$(30); ' clear last message
  134.  
  135. DO
  136.  
  137. CALL SetMousePos(456, 88)  ' start mouse at specified position
  138.  
  139. LOCATE 12, 3
  140. PRINT STRING$(40, 219)
  141. IF HaveMouse THEN CALL ShowMouseCursor
  142. LOCATE 12, 3
  143. FOR i = 1 TO 40
  144.     CALL WaitTicks(1)    ' wait a constant amount of timer ticks
  145.    
  146.     ' mouse should be hidden before displaying anything on screen.
  147.     ' to see effects of not doing this, put mouse in bar while
  148.     ' bar is vanishing.
  149.     ' by putting a call to "hide" just before the following print,
  150.     ' and a call to "show" afterwards, the vanishing bar will not
  151.     ' destroy the mouse pointer. unfortunately, the calls to hide/show
  152.     ' will reset the button press counter (in the mouse driver, so i
  153.     ' can't program around it). thus, by bracketing the following
  154.     ' print with hide/show, you'll get 0 as the number of button presses.
  155.    
  156.     PRINT " "; ' clear the current character in the bar to a blank
  157. NEXT
  158. IF HaveMouse THEN CALL HideMouseCursor
  159.  
  160. BEEP
  161. Button = 0 '  used to tell GetButtonPress that we want data for left button
  162. CALL GetButtonPress(Button, Count, Horiz, Vert)   ' get mouse data
  163.  
  164. LOCATE 15, 1
  165. PRINT SPACE$(78);  'clear line
  166. LOCATE 15, 1
  167. PRINT "Number of presses: "; Count, "Horiz: "; Horiz, "Vert: "; Vert;
  168. PRINT "   (coords of last press)"
  169.  
  170. LOCATE 17, 1
  171. INPUT "Do you want to do this test again (type y or n and hit enter)"; a$
  172.  
  173. LOCATE 15, 1
  174. PRINT SPACE$(79);   ' clear the last status lines
  175. PRINT SPACE$(79);
  176. PRINT SPACE$(79);
  177.  
  178.  
  179. LOOP WHILE a$ <> "n"
  180.  
  181. END SUB
  182.  
  183. '
  184. '  display mouse data at bottom of screen
  185. '
  186. SUB ShowMouseData (Button, Horiz, Vert)
  187.    
  188.     ' display coordinates
  189.     LOCATE 25, 8
  190.     PRINT Horiz;
  191.     LOCATE 25, 20
  192.     PRINT Vert;
  193.   
  194.     ' left button status
  195.     l$ = "UP  "
  196.     IF (Button AND 1) = 1 THEN l$ = "DOWN"
  197.     ' right button status
  198.     r$ = "UP  "
  199.     IF (Button AND 2) = 2 THEN r$ = "DOWN"
  200.     ' center button status
  201.     c$ = "UP  "
  202.     IF (Button AND 4) = 4 THEN c$ = "DOWN"
  203.    
  204.     ' display button status
  205.     LOCATE 25, 33
  206.     PRINT l$;
  207.     LOCATE 25, 48
  208.     PRINT r$;
  209.     LOCATE 25, 64
  210.     PRINT c$;
  211.  
  212.  
  213. END SUB
  214.  
  215.